package com.jrx.mservices.ribbon.controller;

import com.jrx.mservices.ribbon.rule.TestRule;
import com.jrx.mservices.ribbon.service.RibbonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.ReportAsSingleViolation;

/**
 * 消费接口类
 *
 * @author zwg
 * @create 2018-03-06 17:35
 */
@RestController
@RequestMapping("ribbon")
public class RibbonController {

    @Autowired
    private RibbonService ribbonService;

    @Autowired
    private TestRule testRule;

    @RequestMapping("test")
    public String test(){

        return ribbonService.callProvideTestFunc();
    }

    /**
     * 设置服务灰度负载状态
     * @param flg
     * @return
     */
    @GetMapping("gray")
    public String gray(@RequestParam(defaultValue = "false") boolean flg){
        testRule.setGreyLoadBalance(flg);

        return "test rule grayLoadBalance is "+testRule.isGreyLoadBalance();
    }

}
